import cookieJs from "cookies-js"

const TOKEN = "CPToken";
const ROLE = "CPRole";
export default new class cookieStore {

    setCookie(key, value) {
        cookieJs.set(key, value);
    }

    /**
     * 设置带有过期时间的(秒)的cookie
     *
     * @param key
     * @param value
     * @param second
     */
    setCookieWithSecond(key, value, second){
        cookieJs.set(key, value, {expires: second});
    }

    getCookie(key) {
        return cookieJs.get(key);
    }

    removeCookie(key) {
        cookieJs.expire(key);
    }

    setToken(value){
        this.setCookie(TOKEN, value);
    }

    getToken(){
        return this.getCookie(TOKEN);
    }

    removeToken(){
        this.removeCookie(TOKEN);
    }

    setRole(value){
        this.setCookie(ROLE, value);
    }

    getRole(){
        return this.getCookie(ROLE);
    }

    removeRole(){
        this.removeCookie(ROLE);
    }

}